从尾到头打印链表： https://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035?

//方法一，stack方式，这种方式会有内存占用过多的问题
class Solution {
  public:
    vector<int> printListFromTailToHead(ListNode* head) {
        stack<int> s;
        vector<int> v;
        while (head) 
        {
            s.push(head->val);
        }
        while (!s.empty()) 
        {
            v.push_back(s.top());
            s.pop();
        }
        return v;
    }
};
//方法二，逆置数组
class Solution {
  public:
    vector<int> printListFromTailToHead(ListNode* head) {
        vector<int> v;
        while (head) 
        {
            v.push_back(head->val);
            head = head->next;
        }
        reverse(v.begin(), v.end());
        return v;
    }
};
//方法三，递归方式
class Solution {
  public:
    void printListFromTailToHeadCore(ListNode* head, vector<int>& v) {
        if (nullptr == head) 
        {
            return;
        }
        printListFromTailToHeadCore(head->next, v);
        v.push_back(head->val);
    }
    vector<int> printListFromTailToHead(ListNode* head) {
        vector<int> v;
        printListFromTailToHeadCore(head, v);
        return v;
    }
};